import { Global, Module } from '@nestjs/common';
import { DbService } from './db.service';
import { MemberRepositoryModule } from '@app/db/common/member-repository/member-repository.module';
import { MenuRepositoryModule } from '@app/db/common/menu-repository/menu-repository.module';
import { RoleRepositoryModule } from '@app/db/common/role-repository/role-repository.module';
import { DictionaryCategoryRepositoryModule } from '@app/db/common/dictionary-category-repository/dictionary-category-repository.module';
import { DictionaryItemRepositoryModule } from '@app/db/common/dictionary-item-repository/dictionary-item-repository.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigureModule, ConfigureService } from '@app/configure';

import { SysConfigRepositoryModule } from '@app/db/common/sys-config-repository/sys-config-repository.module';
import { UserRepositoryModule } from '@app/db/user-repository/user-repository.module';
import { OfficialUserModule } from '@app/db/official-user/official-user.module';
import { NoticeModule } from '@app/db/notice/notice.module';
import { UserGroupModule } from '@app/db/user-group/user-group.module';
import { DistributionConfigModule } from '@app/db/distribution-config/distribution-config.module';
import { BuyOrderModule } from '@app/db/buy-order/buy-order.module';

@Global()
@Module({
  imports : [
    TypeOrmModule.forRootAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {

       
        
        return {
          ...config.get('db')
        }
      },
    
      // dataSourceFactory: async (options) => {
      // 	const dataSource = await new DataSource(options).initialize();
      // 	return dataSource;
      // },
    }),
    MemberRepositoryModule,
    MenuRepositoryModule,
    RoleRepositoryModule,
    DictionaryCategoryRepositoryModule,
    DictionaryItemRepositoryModule,
    SysConfigRepositoryModule,


   
    UserRepositoryModule,
    UserGroupModule,
    DistributionConfigModule,
    BuyOrderModule,

  ],
  providers: [DbService],
  exports : [DbService]
})
export class DbModule {}
